// package collage.top.cjh;
package cjh;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.omg.CORBA.PRIVATE_MEMBER;

import model.StudentVO;
import model.SubjectVO;

public class Stu_Apend_Register extends JPanel {

	private JCheckBox check[] = new JCheckBox[16]; 
	static String val1[] = new String[3];
	static String val2[] = new String[3];
	static String val3[] = new String[3];
	static String val4[] = new String[3];
	static String val5[] = new String[3];
	static String val6[] = new String[3];
	static String val7[] = new String[3];
	static String val8[] = new String[3];
	static String val9[] = new String[3];
	static String val10[] = new String[3];
	static JPanel okpanel;
	static JPanel dummy;
	static int tot = 0;
	
	public Stu_Apend_Register( StudentVO s ) {
	
		Stu_Service sv = new Stu_Service();
		SubjectVO sb = new SubjectVO();
		System.out.println( s.getDept_no() );
		dummy = new Stu_Temp_Page();
		
		
		// if ( )  - 신청중인 상태이면 미리 보여주어야 함
			
		// Scroll 을 추가할수 있으면 해야된다 - 나중에
		// Grid back layout   cals = 4, row = 0 
		// 목록순서(빈란) _ 과목명 + 배정학점 + 신청여부
		// 1. 신청할 수 있는 과목을 보여줌  -  > select SubJect
		// 2. 학생의 개인 정보를 보임 - 맨아래 보이게
		// 3. 옆에있는 체크박스로 수강신청 내역 체크 
		// 4. 다이얼 창을 띄운 상태에서 재확인
		// 5. 수강신청함에 업데이트
	
		setLayout( new BorderLayout( 0, 0 ));
		
		JPanel indexPanel = new JPanel();
		add( indexPanel, BorderLayout.CENTER );
		
	
				
		indexPanel.setLayout( new GridLayout(0, 4, 0, 0) );
		JPanel subp[] = new JPanel[61];
		JLabel sublbl[] = new JLabel[61];
	
		
		int data = 1;
		for ( SubjectVO v :  sv.serchRegi( s.getDept_no() ) ) {

			if ( data ==1 ){
				setDatas( val1, v);
			}if ( data == 2){
				setDatas( val2, v);
			}if ( data == 3){
				setDatas( val3, v);
			}if ( data == 4){
				setDatas( val4, v);
			}if ( data == 5){
				setDatas( val5, v);
			}if ( data == 6){
				setDatas( val6, v);
			}if ( data == 7){
				setDatas( val7, v);
			}if ( data == 8){
				setDatas( val8, v);
			}if ( data == 9){
				setDatas( val9, v);
			}if ( data == 10){
				setDatas( val10, v);
			}
			
			
			++data; 
		}
		
		
		
		// 체크박스 생성문
		for ( int i = 1; i <= 15 ; i++){
		check[i] = new JCheckBox();
		}
		
		int set = data * 4;
		
		// 패널 생성문 및 체크박스 생성문
		for ( int i = 1 ; i <=set ; i++ ){
				subp[i] = new JPanel();
				sublbl[i] = new JLabel();
			
			if ( i % 4 == 0 ){
				if ( i == 4 ){
					sublbl[i].setText( "신청여부" );
					subp[i].add( sublbl[i] );
					indexPanel.add( subp[i] );
					
					
				}
				else{
				subp[i].add( check[ ( i /  4) ] );
				indexPanel.add( subp[i] );
				}
			}
			else{
				indexPanel.add( subp[i] );
			}
			
					
			if ( i % 4 == 1 ){ // 순번
				sublbl[i].setText( (i / 4) + "" );
				subp[i].add( sublbl[i] );
				
			}
			
			if ( i % 4 == 2) { // 과목이름
			
				sublbl[i].setText( (i) + "" );
				subp[i].add( sublbl[i] );
				
			}
			
			if ( i % 4 == 3) { // 배정학점
				
				sublbl[i].setText( (i) + "" );
				subp[i].add( sublbl[i] );
				
			}
			
		}// for
		sublbl[1].setText( "" );
		sublbl[2].setText( "과목 목록" );
		sublbl[3].setText( "배정 학점" );
		// 과목이름
		if( set >= 6){
		sublbl[6].setText( val1[0] );
		sublbl[6].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val1[0] + "\n" + val1[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if ( set >= 10 ){
		sublbl[10].setText( val2[0] );
		sublbl[10].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val2[0] + "\n" + val2[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}		
		if( set >= 14){
		sublbl[14].setText( val3[0] );
		sublbl[14].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val3[0] + "\n" + val3[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 18){
		sublbl[18].setText( val4[0] );
		sublbl[18].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val4[0] + "\n" + val4[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 22){
		sublbl[22].setText( val5[0] );
		sublbl[22].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val5[0] + "\n" + val5[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 26){
		sublbl[26].setText( val6[0] );
		sublbl[26].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val6[0] + "\n" + val6[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 30){
		sublbl[30].setText( val7[0] );
		sublbl[30].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val7[0] + "\n" + val7[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 34){
		sublbl[34].setText( val8[0] );
		sublbl[34].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val8[0] + "\n" + val8[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 38){
		sublbl[38].setText( val9[0] );
		sublbl[38].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val9[0] + "\n" + val9[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		if( set >= 42){
		sublbl[42].setText( val10[0] );
		sublbl[42].addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if ( e.getClickCount() == 1 ){
					String msg = val10[0] + "\n" + val10[1];
					JOptionPane.showMessageDialog(null, msg);
				}
			}
		});
		}
		
		
		
		
		// 배정학점
		if( set >= 7){
		sublbl[7].setText( val1[2] );
		check[1].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				remove( okpanel );
				okpanel = dummy;
				makebox();
				tot += ( Integer.parseInt( val1[2]) );				
			}
		});
		// check[1].
		
		}
		if( set >= 11){
		sublbl[11].setText( val2[2] );
		}
		if( set >= 15){
		sublbl[15].setText( val3[2] );
		}
		if( set >= 19){
		sublbl[19].setText( val4[2] );
		}
		if( set >= 23){
		sublbl[23].setText( val5[2] );
		}
		if( set >= 27){
		sublbl[27].setText( val6[2] );
		}
		if( set >= 31){
		sublbl[31].setText( val7[2] );
		}
		if( set >= 35){
		sublbl[35].setText( val8[2] );
		}
		if( set >= 39){
		sublbl[39].setText( val9[2] );
		}
		
		//  신청할수 있는 과목 보여주기 
		
		
		
		// 어레이 리스트로 바꿔보기() 
		
		makebox();
		
		
		// 체크 패널 - 신청과목 및 학점 총합 여부 
		
		setVisible(true);
		
		
		
				
		
		
		
		
		
	}// 생성자



	private void setDatas(String[] val, SubjectVO v) {
		val[0] = v.getSub_name();
		val[1] = v.getSub_info();
		val[2] = v.getSub_point();
		
	}
	
	
	private void makebox(){
		JPanel okPanel = new JPanel();
		add( okPanel, BorderLayout.SOUTH );
		
		JLabel tot = new JLabel();
		tot.setText( "신청학점 : ");
		
		JButton in = new JButton();
		in.setText("등록");
		
		
		okPanel.add(tot);
		okPanel.add(in);
		
	}
	
	
	
	
} // class
